package cdu.javaendwork.service.Impl.Shopping;

import cdu.javaendwork.dao.Universal;
import cdu.javaendwork.dao.impl.UniversalImpl;
import cdu.javaendwork.model.sqlModel.Goods;
import cdu.javaendwork.service.Interface.Shopping.GoodsService;

import java.math.BigDecimal;
import java.util.List;

public class GoodsServiceImpl implements GoodsService {

    Universal universal = new UniversalImpl();

    @Override
    public boolean insert(String name, BigDecimal price, int status  , String photo , String description) {
        return universal.insert("Goods" , name , price , status,photo,description ) == 1;
    }

    @Override
    public boolean update(int id, String name, BigDecimal price, int status ,String photo , String description) {
        return universal.updateById("Goods" , id , name , price , status , photo,description) == 1;
    }

    @Override
    public Goods findById(int id) {
        return universal.getById("Goods" , id);
    }

    @Override
    public List<Goods> limit(int pageIndex, int pageSize) {
        return universal.filterLimit("Goods" , "status != 3" , pageIndex , pageSize);
    }

    @Override
    public List<Goods> filterByNameLimit(String where, int pageIndex, int pageSize) {
        return universal.filterLimit("Goods" , "status!=3 and name like '%" + where + "%'" , pageIndex , pageSize);
    }
}
